import sys
import re
from text_classify.data_preprocessing.rule import connect_dict


def match(sentence: str, target: str, rule_dict: dict):
    cat_pos_dict = dict()
    for k, v in rule_dict.items():
        t = str(k)
        cat_name = v[0]
        cat_kw = v[1]
        except_kw = v[2]
        except_cat = v[3]
        for k in cat_kw:
            print(k)
            pos = sentence.find(k)
            if cat_pos_dict.get(t, -1) < pos:
                cat_pos_dict[t] = pos

    print(cat_pos_dict)

    cat = sorted(cat_pos_dict.items(), key=lambda x: x[1], reverse=True)
    print(cat)


def test_match():
    s = '雪完美PXE瓜菜水红葡萄酒多酚面膜3+2片 补水保湿面膜贴正品夏'
    match(s, 'xx', connect_dict)


if __name__ == '__main__':
    test_match()

